package com.song.user.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.song.user.entity.ApiInfo;
import com.song.user.service.ApiInfoService;
import com.song.common.result.ResultEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.ObjectUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.Serializable;
/**
* <p>
    * 菜单信息 控制器
    * </p>
*
* @author song
* @since 2024-06-05
*/
@Api(tags = {"菜单信息 控制器"})
@RestController
@RequestMapping("/api_info")
public class ApiInfoController {

    @Autowired
    ApiInfoService apiInfoService;

    /**
    * 分页查询数据
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "按条件分页检索菜单信息",notes = "按条件分页检索菜单信息")
    @GetMapping(value = "/pageList")
    public ResultEntity<Page<ApiInfo>> pageList(
        @Validated ApiInfo apiInfo,
        @ApiParam(value = "页码", defaultValue = "1")
        @RequestParam(defaultValue = "1") int pageNum,
        @ApiParam(value = "分页大小", defaultValue = "10")
        @RequestParam(defaultValue = "10") int pageSize
    ) {
        Page<ApiInfo> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<ApiInfo> lambda = new QueryWrapper<ApiInfo>().lambda();
        if(ObjectUtils.isNotEmpty(apiInfo.getId())){
            lambda.eq(ApiInfo::getId,apiInfo.getId());
        }
        if(ObjectUtils.isNotEmpty(apiInfo.getApi())){
            lambda.eq(ApiInfo::getApi,apiInfo.getApi());
        }
        if(ObjectUtils.isNotEmpty(apiInfo.getMs())){
            lambda.eq(ApiInfo::getMs,apiInfo.getMs());
        }
        if(ObjectUtils.isNotEmpty(apiInfo.getDj())){
            lambda.eq(ApiInfo::getDj,apiInfo.getDj());
        }
        if(ObjectUtils.isNotEmpty(apiInfo.getFjid())){
            lambda.eq(ApiInfo::getFjid,apiInfo.getFjid());
        }
        if(ObjectUtils.isNotEmpty(apiInfo.getCreateTime())){
            lambda.eq(ApiInfo::getCreateTime,apiInfo.getCreateTime());
        }
        if(ObjectUtils.isNotEmpty(apiInfo.getUpdateTime())){
            lambda.eq(ApiInfo::getUpdateTime,apiInfo.getUpdateTime());
        }
        return ResultEntity.success(apiInfoService.page(page,lambda));
    }

    /**
    * 查询数据List
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "查询全部菜单信息",notes = "查询全部菜单信息")
    @GetMapping(value = "/list")
    public ResultEntity<List<ApiInfo>> list() {
        List<ApiInfo> apiInfoList = apiInfoService.list();
        return ResultEntity.success(apiInfoList);
    }

    /**
    * 菜单信息新增
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "新增菜单信息",notes = "新增菜单信息")
    @PostMapping(value = "/add")
    public ResultEntity add(@RequestBody ApiInfo apiInfo) {
        apiInfoService.save(apiInfo);
        return ResultEntity.success();
    }

    /**
    * 菜单信息修改
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "修改菜单信息",notes = "修改菜单信息")
    @PostMapping(value = "/update")
    public ResultEntity edit(@RequestBody ApiInfo apiInfo) {
        apiInfoService.updateById(apiInfo);
        return ResultEntity.success();
    }

    /**
    * 删除菜单信息
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "按id删除菜单信息",notes = "按id删除菜单信息")
    @PostMapping(value = "/delete")
    public ResultEntity delete(@RequestParam Serializable id) {
        apiInfoService.removeById(id);
        return ResultEntity.success();
    }


    /**
    * 根据id查询菜单信息
    *
    * @author song
    * @Date 2024-06-05
    */
    @ApiOperation(value = "根据id查询菜单信息",notes = "根据id查询修改菜单信息")
    @GetMapping(value = "/detail")
    public ResultEntity<ApiInfo> detail(@RequestParam Serializable id) {
        ApiInfo apiInfo = apiInfoService.getById(id);
        return ResultEntity.success(apiInfo);
    }
}